<script>
	import {
		mapMutations
	} from 'vuex'
	export default {
		onLaunch: function() {
			this.getUserProfile()
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() { 
			console.log('App Hide')
		},
		methods: {
			...mapMutations('m_user', ['updateUserInfo']),
			async getUserProfile() {
				const res = await uni.login().catch(err => err)
				let c = res.code

				// console.log(c)
				// 通过code换取openId
				if (res.errMsg !== 'login:ok') return uni.$showError('获取code失败！！！')
				const {
					data: loginResult
				} = await uni.request({
					url: 'http://8.130.114.82:5555/bbm/user/login',
					method: 'GET',
					data: {
						code: c
					},
					// success: (res) => {
					// 	console.log(res);
					// }
				})
				if (loginResult.code !== 0) return uni.$showMsg('获取用户信息失败！！！')
				// console.log(loginResult)
				const userinfo = loginResult.data
				this.updateUserInfo(userinfo)
			}
		}
	}
</script>

<style lang="scss">
	@import '@/uni_modules/uview-ui/index.scss';
	// @import '@/static/style/iconfont.css';
	@import url("/static/iconfont/iconfont-weapp-icon.css");
	/*每个页面公共css */
</style>